package com.cs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cs.domain.Notice;
import com.cs.domain.vo.NoticeVo;
import com.cs.mapper.NoticeMapper;
import com.cs.service.NoticeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService{

    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * 查询前台的公告
     *
     * @return
     */
    @Override
    public List<NoticeVo> loadTopNoticeList() {
        List<Notice> notices = noticeMapper.selectList(new LambdaQueryWrapper<Notice>()
                .eq(Notice::getStatus, 1).eq(Notice::getShopId, 1L)
                .eq(Notice::getIsTop, 1)
                .orderByDesc(Notice::getPublishTime));
        ArrayList<NoticeVo> noticeVos = new ArrayList<>();
        notices.forEach(notice -> {
            NoticeVo noticeVo = new NoticeVo();
            BeanUtils.copyProperties(notice,noticeVo);
            noticeVos.add(noticeVo);
        });
        return noticeVos;
    }
}
